<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>home</title>
	<link rel="stylesheet" type="text/css" href="${ctx}/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/script/jqgrid/css/jquery-ui-1.8.2.custom.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/script/jqgrid/css/ui.jqgrid.css">

	<script type="text/javascript" src="${ctx}/script/jquery.min.js"></script>
	<script type="text/javascript" src="${ctx}/script/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${ctx}/script/jqgrid/js/i18n/grid.locale-cn.js"></script>
	<script type="text/javascript" src="${ctx}/script/jqgrid/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" src="${ctx}/script/lhgdialog/lhgdialog.min.js?s=facebook"></script>
	
	<style>
	.altclass{
		background: #eeefff;
	}
	</style>

	<script type="text/javascript">
	<!--
		$(function(){
			jQuery("#gridTable").jqGrid({
			   	url:'ywjsglMainFrame.action',
				datatype: 'json',
			   	colNames:['ID','角色名称', '角色说明', '操作'],
			   	colModel:[
			   		{name:'ID', index:'ID',width:55,align:'center',sortable:false,hidden:true},
			   		{name:"LBMC",width:80,align:'center',sortable:false},
				    {name:"SM",width:80,align:'center',sortable:false},
				    {name:'CZ',index:'ID',width:80,fixed:true,sortable:false, resize:false,formatter:cleverActions,formatoptions:{keys:true}}
			   	],
			   	rowNum: 20,
			   	autowidth: true,
				rowList: [1,2,3,4,5,6,7,8,9,10,15,20,30,40,50,100],
				prmNames: {search: "search"},
				jsonReader: {
					root:"gridModel",
					records: "record",
					repeatitems : false
				},
			   	pager: '#gridpager',
			    viewrecords: true,
			    sortname: 'id',
			    //rownumbers: true,
			    multiselect: true,
			    multiboxonly: true,
			    altRows:true,//隔行变色
			    altclass:'altclass',
			    caption:"系统级角色列表"
			});
			$("#gridTable").jqGrid('navGrid','#gridpager',{edit:false,add:false,del:false,search:false,refresh:false});
			
			$("#gridTable").jqGrid().navButtonAdd('#gridpager',{
			   caption:"", 
			   title:"添加新记录",
			   buttonicon:"ui-icon-plus", 
			   onClickButton: function(){ 
			   	   actionOnAdd();
			   }, 
			});
			
			$("#gridTable").jqGrid().navButtonAdd('#gridpager',{
			   caption:"", 
			   title:"删除所选记录",
			   buttonicon:"ui-icon-trash", 
			   onClickButton: function(){ 
		       	   actionOnDel();
			   }
			}).navSeparatorAdd("#gridpager",{position:"first"});
			
			/*
			$("#gridTable").jqGrid().navButtonAdd('#gridpager',{
			   caption:"", 
			   title:"功能授权",
			   buttonicon:"ui-icon-gear", 
			   onClickButton: function(){ 
			   	var rowId = $("#gridTable").getGridParam('selrow');
			    if(rowId) { 
					var rowData = $("#gridTable").getRowData(rowId);
					//new jQuery.dialog({id:'1',title: '功能授权',page:'showGnqxTreePage.action?czlbId='+rowData.ID,width:300,height:450,rang:true,iconTitle:false}).ShowDialog();
					new jQuery.dialog({id:'1',title: '功能授权',page:'view/xt/pzzc/gnsq/ShowGnqxTree.jsp',width:300,height:450,rang:true,iconTitle:false}).ShowDialog();
				} else {
					alert("请选择一行！");
				}
			   }, 
			}).navSeparatorAdd("#gridpager",{position:"first"});
			*/
			
			$("#gridTable").jqGrid().navButtonAdd('#gridpager',{
			   caption:"", 
			   title:"高级查询",
			   buttonicon:"ui-icon-search", 
			   onClickButton: function(){ 
			   	   actionOnSearch();
			   }
			});
			
			doResize();
			
			//test
			$("#snw").click(function (){
				var nw = parseInt(jQuery("#setwidth").val());
				if(isNaN(nw)) {
					alert("Value must be a number");
				} else if (nw<200 || nw > 700) {
					alert("Value can be between 200 and 700")
				} else {
					jQuery("#gridTable").jqGrid('setGridHeight',jQuery("#setwidth").val());
				}
			});
			
			//查询重置按钮
			$("#resetBtn").click(function () {
				document.getElementById("lbmc").value = "";
				document.getElementById("sm").value = "";
				document.getElementById("query").click();
			});
		});
		
		/*
		window.onresize = function() {
			doResize();
		}*/
		
		//设置jqGrid高度
		function doResize() {
			jQuery("#gridTable").jqGrid('setGridHeight',$(document).height()-112);
		}
		
		//行formatter
		function cleverActions(cellvalue, options, rowObject) {
		    return '<div id="' + options.rowId + '" class="ui-corner-all clever-jqgrid-action clever-jqgrid-edit" style="float:left;margin-left:8px;padding:0px;" title="' + $.jgrid.nav.edittitle + '" onclick="actionOnEditLine(this,event);" onmouseover="actionMouseover(this,event)" onmouseout="actionMouseout(this,event)" ><span class="ui-icon ui-icon-pencil"></span></div>'
		    	 + '<div id="' + options.rowId + '" class="ui-corner-all clever-jqgrid-action clever-jqgrid-del"  style="float:left;margin-left:8px;padding:0px;" title="' + $.jgrid.nav.deltitle  + '" onclick="return actionOnDelLine(this,event);" onmouseover="actionMouseover(this,event)" onmouseout="actionMouseout(this,event)" ><span class="ui-icon ui-icon-trash"></span></div>'
		    	 + '<div id="' + options.rowId + '" class="ui-corner-all clever-jqgrid-action clever-jqgrid-gear" style="float:left;margin-left:8px;padding:0px;" title="' + $.jgrid.nav.edittitle + '" onclick="actionOnGnsqLine(this,event);" onmouseover="actionMouseover(this,event)" onmouseout="actionMouseout(this,event)" ><span class="ui-icon ui-icon-gear"></span></div>';
		}
		
		//行formatter鼠标移入样式
		function actionMouseover(el, ev) {
		    $(el).addClass('ui-state-hover');
		    /*
		    if ($.browser.msie) {
		        ev.cancelBubble = true;
		    } else {
		        ev.stopPropagation();
		    }*/
		}
		
		//行formatter鼠标移出样式
		function actionMouseout(el, ev) {
		    $(el).removeClass('ui-state-hover');
		    if ($.browser.msie) {
		        ev.cancelBubble = true;
		    } else {
		        ev.stopPropagation();
		    }
		}

		//行操作-功能授权
		var actionOnGnsqLine = function(el, ev) {  
			var rowId = $(el).attr('id');
		    var rowData = $("#gridTable").getRowData(rowId);
		    new jQuery.dialog({id:'1',title: '功能授权',page:'showGnqxTreePage.action',width:300,height:450,rang:true,iconTitle:false}).ShowDialog();
		};	
		
		//行操作-修改角色
		var actionOnEditLine = function(el, ev) {  
			var rowId = $(el).attr('id');
		    var rowData = $("#gridTable").getRowData(rowId);
			new jQuery.dialog({id:'1',title: '修改角色',page:'addorModGG_CZLB.action?id='+rowData.ID,width:380,height:180,rang:true,iconTitle:false}).ShowDialog();
		};	

		//行操作-删除角色
		var actionOnDelLine = function(el, ev) {
			if(confirm("您确定要删除该记录吗？")) {
				var rowId = $(el).attr('id');
			    var rowData = $("#gridTable").getRowData(rowId);
				var params = {
					"id" : rowData.ID
				};
				var actionUrl = "deleteGG_CZLB.action";
				$.ajax({
					url : actionUrl,
					data : params,
					dataType : "json",
					cache : false,
					error : function(textStatus, errorThrown) {
						alert("系统ajax交互错误: " + textStatus);
					},
					success : function(data, textStatus) {
						if (data.ajaxResult == "success") {
							$("#gridTable").delRowData(rowId);
							alert("删除成功!");
						} else {
							alert("删除操作失败!");
						}
					}
				});
				return true;
			} else {
				return false;
			}
		};
		
		//新增角色
		var actionOnAdd = function() {  
			//showDialog("dialog1","addorModGG_CZLB.action");
			new jQuery.dialog({id:'1',title: '新增角色',page:'addorModGG_CZLB.action',width:380,height:180,rang:true,iconTitle:false}).ShowDialog();
		};  
		
		//删除角色
		var actionOnDel = function() {
			var selr = jQuery('#gridTable').jqGrid('getGridParam','selarrrow');
			if(selr.length) {
				if(confirm("您确定要删除所选记录吗？")) {
					var ids = "";
					for(var i = 0; i < selr.length; i++) {
						//var rowData = $("#gridTable").getRowData(selr[i]);	alert(rowData.ID);
						ids += $('#gridTable').jqGrid('getCell',selr[i],'ID') + ",";
					}
					var params = {
						"id" : ids.substring(0,ids.length-1)
					};
					//alert(params.id);
					var actionUrl = "deleteGG_CZLB.action";
					$.ajax({
						url : actionUrl,
						data : params,
						dataType : "json",
						cache : false,
						error : function(textStatus, errorThrown) {
							alert("系统ajax交互错误: " + textStatus);
						},
						success : function(data, textStatus) {
							if (data.ajaxResult == "success") {
								for(; 0 < selr.length ;) {
									$("#gridTable").delRowData(selr[0]);
								}
								alert("删除成功！");
							} else {
								alert("删除失败！");
							}
						}
					});
					return true;
				}
			} else {
				alert("至少选择一条记录！");
				return false;
			}
		};
		
		var actionOnSearch = function() {
			new jQuery.dialog({id:'1',title: '查询条件',page:'view/xt/pzzc/gnsq/QueryGG_CZLB.jsp',width:380,height:180,rang:true,iconTitle:false}).ShowDialog();
		};
	//-->	
	</script>
</head>
<body>
<form id="form">
	<table title="角色信息" iconCls="icon-title">
		<tbody>
		<tr>
			<td>角色名称:</td>
			<td><input id="lbmc"  name="gg_czlb_cx.lbmc" style="width:150px;" value="${gg_czlb_cx.lbmc}"></td>
			<td>&nbsp;&nbsp;&nbsp;角色说明:</td>
			<td><input id="sm" name="gg_czlb_cx.sm"  style="width:150px;" value="${gg_czlb_cx.sm}"></td>
			<td><input type="submit" id="query" value="查询"/><input type="button" id="resetBtn" value="重置"/></td>
		</tr>
		</tbody>
	</table>
	<!-- 
	<input id="setwidth" type="text" /><input type="button" id="snw" value="Set New Width"/>
	 -->
	<table id="gridTable"></table>
	<div id="gridpager"></div>
</form>	
</body>
</html>